/*     */ package com.wgcloud.controller;
/*     */ 
/*     */ import cn.hutool.json.JSONObject;
/*     */ import cn.hutool.json.JSONUtil;
/*     */ import com.github.pagehelper.PageInfo;
/*     */ import com.wgcloud.entity.FileWarnInfo;
/*     */ import com.wgcloud.entity.FileWarnState;
/*     */ import com.wgcloud.entity.SystemInfo;
/*     */ import com.wgcloud.service.DashboardService;
/*     */ import com.wgcloud.service.ExcelExportService;
/*     */ import com.wgcloud.service.FileWarnInfoService;
/*     */ import com.wgcloud.service.FileWarnStateService;
/*     */ import com.wgcloud.service.HostGroupService;
/*     */ import com.wgcloud.service.LogInfoService;
/*     */ import com.wgcloud.service.SystemInfoService;
/*     */ import com.wgcloud.util.HostUtil;
/*     */ import com.wgcloud.util.PageUtil;
/*     */ import com.wgcloud.util.ResDataUtils;
/*     */ import com.wgcloud.util.TokenUtils;
/*     */ import com.wgcloud.util.license.LicenseUtil;
/*     */ import com.wgcloud.util.staticvar.StaticKeys;
/*     */ import java.util.HashMap;
/*     */ import java.util.List;
/*     */ import java.util.Map;
/*     */ import javax.annotation.Resource;
/*     */ import javax.servlet.http.HttpServletRequest;
/*     */ import javax.servlet.http.HttpServletResponse;
/*     */ import org.apache.commons.lang3.StringUtils;
/*     */ import org.slf4j.Logger;
/*     */ import org.slf4j.LoggerFactory;
/*     */ import org.springframework.beans.factory.annotation.Autowired;
/*     */ import org.springframework.stereotype.Controller;
/*     */ import org.springframework.ui.Model;
/*     */ import org.springframework.web.bind.annotation.RequestBody;
/*     */ import org.springframework.web.bind.annotation.RequestMapping;
/*     */ import org.springframework.web.bind.annotation.ResponseBody;
/*     */ import org.springframework.web.servlet.mvc.support.RedirectAttributes;
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ @Controller
/*     */ @RequestMapping({"/fileWarnInfo"})
/*     */ public class FileWarnInfoController
/*     */ {
/*  47 */   private static final Logger logger = LoggerFactory.getLogger(com.wgcloud.controller.FileWarnInfoController.class);
/*     */ 
/*     */   
/*     */   @Resource
/*     */   private FileWarnInfoService fileWarnInfoService;
/*     */ 
/*     */   
/*     */   @Resource
/*     */   private FileWarnStateService fileWarnStateService;
/*     */ 
/*     */   
/*     */   @Resource
/*     */   private LogInfoService logInfoService;
/*     */ 
/*     */   
/*     */   @Resource
/*     */   private DashboardService dashBoardService;
/*     */ 
/*     */   
/*     */   @Resource
/*     */   private SystemInfoService systemInfoService;
/*     */ 
/*     */   
/*     */   @Resource
/*     */   private HostGroupService hostInfoService;
/*     */ 
/*     */   
/*     */   @Resource
/*     */   private ExcelExportService excelExportService;
/*     */   
/*     */   @Autowired
/*     */   private TokenUtils tokenUtils;
/*     */ 
/*     */   
/*     */   @ResponseBody
/*     */   @RequestMapping({"agentList"})
/*     */   public String agentList(@RequestBody String paramBean) {
/*  84 */     JSONObject agentJsonObject = (JSONObject)JSONUtil.parse(paramBean);
/*  85 */     if (!this.tokenUtils.checkAgentToken(agentJsonObject)) {
/*  86 */       logger.error("token is error");
/*  87 */       return ResDataUtils.resetErrorJson("token is error");
/*     */     } 
/*  89 */     Map<String, Object> params = new HashMap<>();
/*  90 */     if (null == agentJsonObject.get("hostname") || StringUtils.isEmpty(agentJsonObject.get("hostname").toString())) {
/*  91 */       return "";
/*     */     }
/*  93 */     params.put("hostname", agentJsonObject.get("hostname").toString());
/*     */     try {
/*  95 */       params.put("active", "1");
/*  96 */       List<FileWarnInfo> FileWarnInfoList = this.fileWarnInfoService.selectAllByParams(params);
/*  97 */       return ResDataUtils.resetSuccessJson(FileWarnInfoList);
/*  98 */     } catch (Exception e) {
/*  99 */       logger.error("agent获取日志监控信息错误", e);
/* 100 */       this.logInfoService.save("agent获取日志监控信息错误", e.toString(), "1");
/* 101 */       return ResDataUtils.resetErrorJson(e.toString());
/*     */     } 
/*     */   }
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */   
/*     */   @ResponseBody
/*     */   @RequestMapping({"agentStateListList"})
/*     */   public String agentStateListList(@RequestBody String paramBean) {
/* 115 */     JSONObject agentJsonObject = (JSONObject)JSONUtil.parse(paramBean);
/* 116 */     if (!this.tokenUtils.checkAgentToken(agentJsonObject)) {
/* 117 */       logger.error("token is invalidate");
/* 118 */       return ResDataUtils.resetErrorJson("token is invalidate");
/*     */     } 
/* 120 */     Map<String, Object> params = new HashMap<>();
/* 121 */     if (null == agentJsonObject.get("fileWarnId") || StringUtils.isEmpty(agentJsonObject.get("fileWarnId").toString())) {
/* 122 */       return "";
/*     */     }
/* 124 */     params.put("fileWarnId", agentJsonObject.get("fileWarnId").toString());
/*     */     try {
/* 126 */       PageInfo pageInfo = this.fileWarnStateService.selectByParams(params, agentJsonObject.getInt("page").intValue(), agentJsonObject.getInt("pageSize").intValue());
/* 127 */       JSONObject pageJson = new JSONObject();
/* 128 */       pageJson.set("total", Long.valueOf(pageInfo.getTotal()));
/* 129 */       pageJson.set("pages", Integer.valueOf(pageInfo.getPages()));
/* 130 */       pageJson.set("page", agentJsonObject.getInt("page"));
/* 131 */       pageJson.set("pageSize", agentJsonObject.getInt("pageSize"));
/* 132 */       pageJson.set("list", pageInfo.getList());
/* 133 */       return ResDataUtils.resetSuccessJson(pageJson);
/* 134 */     } catch (Exception e) {
/* 135 */       logger.error("agent获取日志监控状态信息错误", e);
/* 136 */       this.logInfoService.save("agent获取日志监控状态信息错误", e.toString(), "1");
/* 137 */       return ResDataUtils.resetErrorJson(e.toString());
/*     */     } 
/*     */   }
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */   
/*     */   @RequestMapping({"list"})
/*     */   public String FileWarnInfoList(FileWarnInfo fileWarnInfo, Model model, HttpServletRequest request) {
/* 150 */     Map<String, Object> params = new HashMap<>();
/*     */     
/*     */     try {
/* 153 */       LicenseUtil.maxLicense_10(model, request);
/*     */ 
/*     */       
/* 156 */       StringBuffer url = new StringBuffer();
/* 157 */       String hostname = null;
/* 158 */       if (!StringUtils.isEmpty(fileWarnInfo.getHostname())) {
/* 159 */         hostname = fileWarnInfo.getHostname();
/* 160 */         params.put("hostname", hostname.trim());
/* 161 */         url.append("&hostname=").append(hostname);
/*     */       } 
/* 163 */       if (!StringUtils.isEmpty(fileWarnInfo.getOrderBy())) {
/* 164 */         params.put("orderBy", fileWarnInfo.getOrderBy());
/* 165 */         params.put("orderType", fileWarnInfo.getOrderType());
/* 166 */         url.append("&orderBy=").append(fileWarnInfo.getOrderBy());
/* 167 */         url.append("&orderType=").append(fileWarnInfo.getOrderType());
/*     */       } 
/* 169 */       PageInfo<FileWarnInfo> pageInfo = this.fileWarnInfoService.selectByParams(params, fileWarnInfo.getPage().intValue(), fileWarnInfo.getPageSize().intValue());
/* 170 */       for (FileWarnInfo fileWarnInfo1 : pageInfo.getList()) {
/* 171 */         fileWarnInfo1.setHostname(fileWarnInfo1.getHostname() + HostUtil.addRemark(fileWarnInfo1.getHostname()));
/*     */       }
/* 173 */       PageUtil.initPageNumber(pageInfo, model);
/* 174 */       model.addAttribute("pageUrl", "/fileWarnInfo/list?1=1" + url.toString());
/* 175 */       model.addAttribute("page", pageInfo);
/* 176 */       model.addAttribute("fileWarnInfo", fileWarnInfo);
/* 177 */     } catch (Exception e) {
/* 178 */       logger.error("查询日志监控信息错误", e);
/* 179 */       this.logInfoService.save("查询日志监控信息错误", e.toString(), "1");
/*     */     } 
/*     */     
/* 182 */     return "file/list";
/*     */   }
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */   
/*     */   @RequestMapping({"save"})
/*     */   public String saveFileWarnInfo(FileWarnInfo fileWarnInfo, Model model, HttpServletRequest request) {
/*     */     try {
/* 197 */       if (StringUtils.isEmpty(fileWarnInfo.getId())) {
/* 198 */         fileWarnInfo.setWarnRows("0");
/* 199 */         fileWarnInfo.setFileSize("0");
/* 200 */         this.fileWarnInfoService.save(fileWarnInfo);
/*     */       } else {
/* 202 */         this.fileWarnInfoService.updateById(fileWarnInfo);
/*     */       } 
/* 204 */     } catch (Exception e) {
/* 205 */       logger.error("保存日志监控错误", e);
/* 206 */       this.logInfoService.save("保存日志监控错误", e.toString(), "1");
/*     */     } 
/* 208 */     return "redirect:/fileWarnInfo/list";
/*     */   }
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */   
/*     */   @RequestMapping({"saveBatch"})
/*     */   public String saveBatchFileWarnInfo(FileWarnInfo fileWarnInfo, Model model, HttpServletRequest request) {
/*     */     try {
/* 223 */       String[] hostnames = request.getParameterValues("hostnames");
/* 224 */       if (null == hostnames || hostnames.length < 1) {
/* 225 */         return "redirect:/fileWarnInfo/list";
/*     */       }
/* 227 */       for (String selectedHost : hostnames) {
/* 228 */         fileWarnInfo.setHostname(selectedHost);
/* 229 */         fileWarnInfo.setWarnRows("0");
/* 230 */         fileWarnInfo.setFileSize("0");
/* 231 */         this.fileWarnInfoService.save(fileWarnInfo);
/*     */       } 
/* 233 */     } catch (Exception e) {
/* 234 */       logger.error("批量保存日志监控错误", e);
/* 235 */       this.logInfoService.save("批量保存日志监控错误", e.toString(), "1");
/*     */     } 
/* 237 */     return "redirect:/fileWarnInfo/list";
/*     */   }
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */   
/*     */   @RequestMapping({"edit"})
/*     */   public String edit(Model model, HttpServletRequest request) {
/* 249 */     String errorMsg = "添加日志监控";
/* 250 */     String id = request.getParameter("id");
/* 251 */     FileWarnInfo FileWarnInfo = new FileWarnInfo();
/*     */     try {
/* 253 */       List<SystemInfo> systemInfoList = this.systemInfoService.selectAllByParams(new HashMap<>());
/* 254 */       model.addAttribute("systemInfoList", systemInfoList);
/* 255 */       if (StringUtils.isEmpty(id)) {
/* 256 */         model.addAttribute("fileWarnInfo", FileWarnInfo);
/*     */ 
/*     */         
/* 259 */         Map<String, Object> params = new HashMap<>();
/* 260 */         int dbSize = this.fileWarnInfoService.countByParams(params).intValue();
/* 261 */         if (dbSize >= 10 && !StaticKeys.LICENSE_STATE.equals("1")) {
/* 262 */           return "redirect:/fileWarnInfo/list?liceFlage=1";
/*     */         }
/*     */ 
/*     */         
/* 266 */         return "file/add";
/*     */       } 
/* 268 */       FileWarnInfo = this.fileWarnInfoService.selectById(id);
/* 269 */       model.addAttribute("fileWarnInfo", FileWarnInfo);
/* 270 */     } catch (Exception e) {
/* 271 */       logger.error(errorMsg, e);
/* 272 */       this.logInfoService.save(errorMsg, e.toString(), "1");
/*     */     } 
/* 274 */     return "file/add";
/*     */   }
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */   
/*     */   @RequestMapping({"editBatch"})
/*     */   public String editBatch(Model model, HttpServletRequest request) {
/* 286 */     String errorMsg = "批量添加日志监控";
/* 287 */     FileWarnInfo FileWarnInfo = new FileWarnInfo();
/*     */     try {
/* 289 */       List<SystemInfo> systemInfoList = this.systemInfoService.selectAllByParams(new HashMap<>());
/* 290 */       model.addAttribute("systemInfoList", systemInfoList);
/* 291 */       model.addAttribute("fileWarnInfo", FileWarnInfo);
/*     */ 
/*     */       
/* 294 */       Map<String, Object> params = new HashMap<>();
/* 295 */       int dbSize = this.fileWarnInfoService.countByParams(params).intValue();
/* 296 */       if (dbSize >= 10 && !StaticKeys.LICENSE_STATE.equals("1")) {
/* 297 */         return "redirect:/fileWarnInfo/list?liceFlage=1";
/*     */       
/*     */       }
/*     */     }
/* 301 */     catch (Exception e) {
/* 302 */       logger.error(errorMsg, e);
/* 303 */       this.logInfoService.save(errorMsg, e.toString(), "1");
/*     */     } 
/* 305 */     return "file/addBatch";
/*     */   }
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */   
/*     */   @RequestMapping({"view"})
/*     */   public String view(Model model, HttpServletRequest request) {
/* 317 */     String errorMsg = "查看日志监控";
/* 318 */     String id = request.getParameter("id");
/* 319 */     FileWarnInfo FileWarnInfo = new FileWarnInfo();
/*     */     try {
/* 321 */       FileWarnInfo = this.fileWarnInfoService.selectById(id);
/* 322 */       model.addAttribute("fileWarnInfo", FileWarnInfo);
/* 323 */     } catch (Exception e) {
/* 324 */       logger.error(errorMsg, e);
/* 325 */       this.logInfoService.save(errorMsg, e.toString(), "1");
/*     */     } 
/* 327 */     return "file/view";
/*     */   }
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */   
/*     */   @RequestMapping({"stateList"})
/*     */   public String stateList(FileWarnState fileWarnState, Model model, HttpServletRequest request) {
/* 340 */     Map<String, Object> params = new HashMap<>();
/*     */     try {
/* 342 */       StringBuffer url = new StringBuffer();
/* 343 */       FileWarnInfo fileWarnInfo = null;
/* 344 */       if (!StringUtils.isEmpty(fileWarnState.getFileWarnId())) {
/* 345 */         fileWarnInfo = this.fileWarnInfoService.selectById(fileWarnState.getFileWarnId());
/* 346 */         params.put("fileWarnId", fileWarnState.getFileWarnId());
/* 347 */         url.append("&fileWarnId=").append(fileWarnState.getFileWarnId());
/*     */       } 
/* 349 */       PageInfo pageInfo = this.fileWarnStateService.selectByParams(params, fileWarnState.getPage().intValue(), fileWarnState.getPageSize().intValue());
/* 350 */       PageUtil.initPageNumber(pageInfo, model);
/* 351 */       model.addAttribute("pageUrl", "/fileWarnInfo/stateList?1=1" + url.toString());
/* 352 */       model.addAttribute("page", pageInfo);
/*     */       
/* 354 */       fileWarnInfo.setHostname(fileWarnInfo.getHostname() + HostUtil.addRemark(fileWarnInfo.getHostname()));
/*     */       
/* 356 */       model.addAttribute("fileWarnInfo", fileWarnInfo);
/* 357 */     } catch (Exception e) {
/* 358 */       logger.error("查询日志监控信息错误", e);
/* 359 */       this.logInfoService.save("查询日志监控信息错误", e.toString(), "1");
/*     */     } 
/*     */     
/* 362 */     return "file/stateList";
/*     */   }
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */   
/*     */   @RequestMapping({"chartExcel"})
/*     */   public void chartExcel(Model model, HttpServletRequest request, HttpServletResponse response) {
/* 374 */     String errorMsg = "日志监控信息导出excel错误";
/* 375 */     String id = request.getParameter("id");
/*     */     try {
/* 377 */       if (!StaticKeys.LICENSE_STATE.equals("1")) {
/* 378 */         response.setContentType("text/html;charset=UTF-8");
/* 379 */         response.getOutputStream().write("The excel needs to wgcloud-pro version".getBytes());
/*     */         return;
/*     */       } 
/* 382 */       Map<String, Object> params = new HashMap<>();
/* 383 */       if (StringUtils.isEmpty(id)) {
/* 384 */         response.setContentType("text/html;charset=UTF-8");
/* 385 */         response.getOutputStream().write("The excel must  require parameters".getBytes());
/*     */         return;
/*     */       } 
/* 388 */       FileWarnInfo fileWarnInfo = this.fileWarnInfoService.selectById(id);
/* 389 */       params.put("fileWarnId", id);
/* 390 */       this.excelExportService.exportFileWarnStateExcel(fileWarnInfo, params, response);
/* 391 */     } catch (Exception e) {
/* 392 */       logger.error(errorMsg, e);
/* 393 */       this.logInfoService.save(errorMsg, e.toString(), "1");
/*     */     } 
/*     */   }
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */   
/*     */   @RequestMapping({"stateView"})
/*     */   public String stateView(FileWarnState fileWarnState, Model model, HttpServletRequest request) {
/* 406 */     Map<String, Object> params = new HashMap<>();
/*     */     try {
/* 408 */       fileWarnState = this.fileWarnStateService.selectById(fileWarnState.getId());
/* 409 */       model.addAttribute("fileWarnState", fileWarnState);
/* 410 */     } catch (Exception e) {
/* 411 */       logger.error("查询日志监控信息详情错误", e);
/* 412 */       this.logInfoService.save("查询日志监控信息详情错误", e.toString(), "1");
/*     */     } 
/*     */     
/* 415 */     return "file/stateView";
/*     */   }
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */   
/*     */   @RequestMapping({"del"})
/*     */   public String delete(Model model, HttpServletRequest request, RedirectAttributes redirectAttributes) {
/* 430 */     String errorMsg = "删除日志监控信息错误";
/* 431 */     FileWarnInfo FileWarnInfo = new FileWarnInfo();
/*     */     try {
/* 433 */       if (!StringUtils.isEmpty(request.getParameter("id"))) {
/* 434 */         String[] ids = request.getParameter("id").split(",");
/* 435 */         for (String id : ids) {
/* 436 */           FileWarnInfo = this.fileWarnInfoService.selectById(id);
/* 437 */           this.logInfoService.save("删除日志监控：" + FileWarnInfo.getHostname(), "删除日志监控：" + FileWarnInfo.getHostname(), "0");
/*     */         } 
/* 439 */         this.fileWarnInfoService.deleteById(ids);
/*     */       } 
/* 441 */     } catch (Exception e) {
/* 442 */       logger.error(errorMsg, e);
/* 443 */       this.logInfoService.save(errorMsg, e.toString(), "1");
/*     */     } 
/* 445 */     return "redirect:/fileWarnInfo/list";
/*     */   }
/*     */ }


/* Location:              /Users/zhangyongxin/soft-install/wgcloud/wgcloud-v3.3.5/server/bank/wgcloud-server-release.jar!/BOOT-INF/classes/com/wgcloud/controller/FileWarnInfoController.class
 * Java compiler version: 8 (52.0)
 * JD-Core Version:       1.1.3
 */